<template>
  <div>
    <div style="display:flex;flex-direction:row-reverse;margin-top:10px">
      <el-button :disabled="submitLoading" size="mini" type="primary" @click="submitForm(0)">保存</el-button>
      <el-button style="margin-right:20px" :disabled="submitLoading" size="mini" type="primary" @click="submitForm(1)">提交</el-button>
    </div>
    <div v-loading="dataLoading">
      <base-info :base-info="detailData" />
      <!-- <drawing-info :base-info="detailData" /> -->
      <div style="margin-top:20px" class="qup-title-box"><span class="border" /><span>配图分配信息</span></div>

      <el-form
        ref="refForm"
        :rules="formRules"
        :model="formData"
        size="mini"
        label-width="150px"
      >
        <el-row>
          <el-col :span="8">
            <el-form-item label="上传配图确认时间:" prop="drawingCollectTime">
              <el-input v-model="formData.drawingCollectTime" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :rules="[{ required: true, message: '请选择设计师', trigger: 'change' }]" label="配置设计师:" prop="configurationDesigner">
              <input-with-dialog
                v-model="designer"
                :props="{label:'userName',value:'account'}"
                multiple
                :config="{
                  title:'设计师',
                  width:'600px',
                  interfacePath:`/slm-admin/api/v1/user/listUsers`,
                  method:'post',
                  filtersRaw:[],
                  paramsRaw:{},
                  setting:[
                    {prop:'account',title:'编码'},
                    {prop:'userName',title:'名称'}
                  ]
                }"
                @change="handleChangeDesigner"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="分配设计师时间:" prop="drawingAllocationTime">
              <el-input v-model="formData.drawingAllocationTime" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="加急:" prop="urgent">
              <el-input v-model="formData.urgent" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>
<script>
import BackPageMixin from '@/mixins/backPage'
import { queryDetail, submitAllotDesginer } from '@/api/autoDesignTask'
import baseInfo from './component/BaseInfo.vue'
import drawingInfo from './component/DrawingInfo.vue'

export default {
  name: 'EditAutoDesignTask',
  components: { baseInfo, drawingInfo },
  mixins: [BackPageMixin],
  props: {
  },
  data() {
    return {
      id: '',
      detailData: {},
      designer: [],
      submitLoading: false,
      dataLoading: false,
      formData: {
        id: ''
      },
      formRules: {
      }
    }
  },
  watch: {
  },
  async  created() {
    this.id = this.$route.query.id
    if (this.id) {
      this.dataLoading = true
      queryDetail(this.id).then(res => {
        if (res.success) {
          this.detailData = res.data
          const { id, configurationDesigner, drawingDesignerCode, drawingCollectTime, createTime, urgent } = res.data
          this.formData = { id, configurationDesigner, drawingDesignerCode, drawingCollectTime, createTime, urgent }
          this.designer = [{ value: this.formData.drawingDesignerCode, label: this.formData.configurationDesigner }]
          this.dataLoading = false
        }
      })
    }
    this.dataLoading = false
  },
  mounted() {
  },
  methods: {

    handleChangeDesigner(data) {
      if (data && data.length > 0) {
        const list1 = data.map(v => v.userName)
        const list2 = data.map(v => v.account)
        this.$set(this.formData, 'configurationDesigner', list1.join(','))
        this.$set(this.formData, 'drawingDesignerCode', list2.join(','))
      } else {
        this.$set(this.formData, 'configurationDesigner', '')
        this.$set(this.formData, 'drawingDesignerCode', '')
      }
    },
    goBack() {
      this.$store.dispatch('views/goBack')
    },
    async   submitForm(type) {
      if (this.submitLoading) return
      this.$refs['refForm'].validate((valid) => {
        if (valid) {
          this.submitLoading = true
          submitAllotDesginer(this.formData, type).then(res => {
            if (res.success) {
              this.submitLoading = false
              this.$message.success('操作成功')
              this.goBack()
            }
          }).catch(() => {
            this.submitLoading = false
          })
        }
      })
    }

  }
}
</script>
<style lang="scss" scoped>
/deep/ .el-breadcrumb__inner{
    color: $qup-color-primary;
  }
</style>
